package com.vert.controller;

import com.alibaba.fastjson.JSONObject;
import com.vert.annotations.GetMapping;
import com.vert.annotations.Param;
import com.vert.annotations.RestController;
import com.vert.utils.JarScanUtils;
import com.vert.utils.ObjectMaps;
import com.vert.utils.Results;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @Classname JarController
 * @Description TODO
 * @Date 2022/6/1 16:29
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController(value = "/jar",desc = "jar扫描")
public class JarController {

    @GetMapping("/test")
    public JSONObject scanController(@Param("path")String path){
        try {
          JarScanUtils.clear();
          Set<Class<?>> cls=JarScanUtils.loadAllJarFromAbsolute(path);
          for (Class< ? > c : cls) {
              addClazz(c);
          }
        }catch (Exception e){
          e.printStackTrace();
        }
        return Results.success();
    }

    private void addClazz(Class<?> cls){

        RestController res=cls.getAnnotation(RestController.class);
        try {
          if(res != null){
             ObjectMaps.createClazz(cls);
          }
        }catch (Exception e){
          e.printStackTrace();
        }
    }
}
